<template>
  <div class="seller" ref="seller">
    <div class="seller-content">
      <div class="overview">
        <h1 class="title">{{seller.name}}</h1>
        <div class="desc">
          <star :size="36" :score="seller.score"></star>
          <span class="text">({{seller.ratingCount}})</span>
          <span class="text">月售{{seller.sellCount}}单</span>
        </div>
        <ul class="remark">
          <li class="block border-right">
            <h2 class="title">起送价</h2>
            <div class="content">
              <span class="stress">{{seller.minPrice}}</span>元
            </div>
          </li>
          <li class="block border-right">
            <h2 class="title">商家配送</h2>
            <div class="content">
              <span class="stress">{{seller.deliveryPrice}}</span>元
            </div>
          </li>
          <li class="block">
            <h2 class="title">平均配送时间</h2>
            <div class="content">
              <span class="stress">{{seller.deliveryTime}}</span>分钟
            </div>
          </li>
        </ul>
        <div class="favorite" @click="toggleFavorite">
          <span class="icon-favorite" :class="{'active': favorite}"></span>
          <span class="text">{{favoriteText}}</span>
        </div>
      </div>
      <split></split>
      <div class="bulletin">
        <h1 class="title">公告与活动</h1>
        <div class="content-wrapper">
          <p class="content">{{seller.bulletin}}</p>
        </div>
        <ul class="supports" v-if="seller.supports">
          <li
            class="support-item"
            v-for="item in seller.supports"
            :key="item.type"
          >
              <span
                class="icon"
                :class="classMap[seller.supports[item.type].type]"
              ></span>
            <span class="text">{{seller.supports[item.type].description}}</span>
          </li>
        </ul>
      </div>
      <split></split>
      <div class="pics">
        <h1 class="title">商家实景</h1>
        <div class="pic-wrapper" ref="picWrapper">
          <ul class="pic-list" ref="picList">
            <li
              class="pic-item"
              v-for="(pic,index) in seller.pics"
              :key="index"
            >
              <img :src="pic" alt="">
            </li>
          </ul>
        </div>
      </div>
      <split></split>
      <div class="info">
        <h1 class="title">商家信息</h1>
        <ul>
          <li class="info-item" v-for="(item,index) in seller.infos" :key="index">{{item}}</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import star from '../../../star/star.vue'
import split from '../../../split/split.vue'
import Bscroll from 'better-scroll'
export default {
  name: 'TabSeller',
  props: {
    seller: Object
  },
  components: {
    star,
    split
  },
  data () {
    return {
      favorite: false
    }
  },
  computed: {
    favoriteText () {
      return this.favorite ? '已收藏' : '未收藏'
    }
  },
  created () {
    this.classMap = ['decrease', 'discount', 'special', 'invoice', 'guarantee']
  },
  mounted () {
    this._initScroll()
    this._initPicScroll()
  },
  /*
  watch: {
    // 当 watch 到 seller 生成时 就可以执行 _initPicScroll 方法
    'seller' () {
      this.$nextTick(() => {
        this._initPicScroll()
      })
    }
  },
  */
  methods: {
    _initScroll () {
      this.scroll = new Bscroll(this.$refs.seller)
    },
    _initPicScroll () {
      if (this.seller.pics) {
        let picWidth = 120
        let margin = 6
        let width = this.seller.pics.length * (picWidth + margin) - margin
        this.$refs.picList.style.width = width + 'px'
        this.picScroll = new Bscroll(this.$refs.picWrapper, {
          scrollX: true,
          eventPassthrough: 'vertical'
        })
      }
    },
    toggleFavorite () {
      this.favorite = !this.favorite
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "../../../../common/stylus/mixin.styl"
  .seller
    position absolute
    top 3.48rem
    left 0
    right 0
    bottom 0
    width 100%
    overflow hidden
    .overview
      position relative
      padding .36rem
      .title
        margin-bottom .16rem
        line-height .28rem
        font-size .28rem
        font-weight 700
        color rgb(7,17,27)
      .desc
        padding-bottom  .36rem
        font-size 0
        border-bottom 1px solid #eaeaea
        .star
          vertical-align top
          display inline-block
          margin-right .16rem
        .text
          vertical-align top
          display inline-block
          margin-right .24rem
          line-height .36rem
          font-size .20rem
          color rgb(77,85,93)
      .remark
        display flex
        margin-top .36rem
        .block
          flex 1
          border-right 1px solid #eaeaea
          &:last-child
            border none
          .title
            text-align center
            margin-bottom .08rem
            line-height .2rem
            font-size .2rem
            color rgb(147,153,159)
          .content
            text-align center
            font-size .20rem
            font-weight 200
            color rgb(7,17,27)
            .stress
              line-height .48rem
              font-size .48rem
              font-weight 200
              color rgb(7,17,27)
      .favorite
        position absolute
        right .36rem
        top .36rem
        width 1rem
        text-align center
        .icon-favorite
          display block
          margin-bottom .08rem
          line-height .48rem
          font-size .48rem
          color #d4d6d9
          &.active
            color red
        .text
          line-height .2rem
          font-size .2rem
          color: rgb(77, 85, 93)
    .bulletin
      padding .36rem .36rem 0 .36rem
      .title
        margin-bottom .16rem
        line-height .28rem
        font-size .28rem
        font-weight 700
        color rgb(7,17,27)
      .content-wrapper
        padding 0 .24rem .32rem .24rem
        border-bottom 1px solid rgba(7,17,.27,.1)
        .content
          line-height .48rem
          font-size .24rem
          font-weight 200
          color rgb(240,20,20)
      .supports
        .support-item
          padding .32rem .24rem
          border-bottom 1px solid #eaeaea
          .icon
            display inline-block
            vertical-align top
            margin-right .12rem
            width .32rem
            height .32rem
            background-size .32rem .32rem
            background-repeat no-repeat
            &.decrease
              bg-image('decrease_4')
            &.discount
              bg-image('discount_4')
            &.guarantee
              bg-image('guarantee_4')
            &.invoice
              bg-image('invoice_4')
            &.special
              bg-image('special_4')
    .pics
      padding .36rem 0 .36rem .36rem
      .title
        margin-bottom .24rem
        line-height .28rem
        font-size .28rem
        font-weight 700
        color rgb(7,17,27)
      .pic-wrapper
        overflow hidden
        width 100%
        // 当我们内容超过了屏幕的最大宽度的时候，不会被隔行
        white-space nowrap
        .pic-list
          font-size 0
          .pic-item
            display inline-block
            margin-right .12rem
            width 2.4rem
            height 1.8rem
            & > img
              width 2.4rem
              height 2.4rem
    .info
      padding .36rem .36rem 0 .36rem
      .title
        margin-bottom .24rem
        line-height .28rem
        font-size .28rem
        font-weight 700
        color rgb(7,17,27)
      .info-item
        padding .32rem .24rem
        line-height .32rem
        font-size .24rem
        font-weight 200
        color rgb(7,17,27)
        border-top 1px solid #eaeaea
</style>
